package com.lam.monitor.domain;

import java.lang.management.ManagementFactory;

import com.lam.common.utils.DateUtil;
import com.lam.common.utils.NumberUtil;

/**
 * JVM相关信息
 * 
 * @author lam
 */
public class Jvm {
	/**
	 * 当前JVM占用的内存总数(M)
	 */
	private double total;

	/**
	 * JVM最大可用内存总数(M)
	 */
	private double max;

	/**
	 * JVM空闲内存(M)
	 */
	private double free;

	/**
	 * JDK版本
	 */
	private String version;

	/**
	 * JDK路径
	 */
	private String home;
	
	private String convertM(double n) {
		return NumberUtil.DF_2.format(n/1024/1024);
	}

	public String getTotal() {
		
		return convertM(total);
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public String getMax() {
		return convertM(max);
	}

	public void setMax(double max) {
		this.max = max;
	}

	public String getFree() {
		return convertM(free);
	}

	public void setFree(double free) {
		this.free = free;
	}

	public String getUsed() {
		return convertM(total - free);
	}

	public String getUsage() {
		return NumberUtil.DF_2.format((total - free)/total * 100);
	}

	/**
	 * 获取JDK名称
	 */
	public String getName() {
		return ManagementFactory.getRuntimeMXBean().getVmName();
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getHome() {
		return home;
	}

	public void setHome(String home) {
		this.home = home;
	}

	/**
	 * JDK启动时间
	 */
	public String getStartTime() {
		return DateUtil.formatDate(DateUtil.getServerStartDate(), DateUtil.PATTERN_DEFAULT);
	}

	/**
	 * JDK运行时间
	 */
	public String getRunTime() {
		return DateUtil.getDatePoor(DateUtil.newDate(), DateUtil.getServerStartDate());
	}
}
